window.onload=function(){
	focuson();
}

function focuson(){
	var username=document.getElementById('username');
	var password=document.getElementById('password');
	username.onfocus=function () {
		if (this.value=="用户名") {
			this.value="";
		username.style.color="black";
		}	
	}	

	password.onfocus=function () {
		if (this.value=="密码") {
			this.value="";
			this.type="password";
		password.style.color="black";
		}	
	}
}

function login(){
	if($('#username').val()=='admin' && $('#password').val()=='admin')
		{
			window.location.href="../admin/admin-index.html";
		}else{

	$.ajax({
		url:'http://172.18.21.150/ToGo/login',
		type:'POST',
		dataType:'json',
		data:{username: $('#username').val(),password:$('#password').val()},
		success:function(result){
			if (result.status=='200') {
				$.cookie('username',result.data.username, {path: '/'});
				$.cookie('userid',result.data.user_id, {path: '/'});
				window.location.href="../car/index.html";
			}
		},
		error:function() {
			 alert("错误");
		}
	});
}
}

// function setCookie(name,value)
// {
// var Days = 30;
// var exp = new Date();
// exp.setTime(exp.getTime() + Days*24*60*60*1000);
// document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
// }